package com.exigenservices.practice.roadcompanion.web;

import com.exigenservices.practice.roadcompanion.server.dto.RegistrationDTO;
import org.apache.log4j.Logger;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import javax.servlet.http.HttpServletRequest;

//TODO rename
public class pageReg extends SimpleFormController {
    private static Logger LOGGER = Logger.getLogger(pageReg.class.getName());
    @Override
    protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception {

        return new RegistrationDTO();
    }
    /*
    @Override
    protected Map referenceData(HttpServletRequest httpServletRequest) throws Exception {
        Map<String, Object> attributes = new HashMap<String, Object>(1);
        return attributes;
    }       */

    @Override
    protected ModelAndView onSubmit(Object command, BindException e) throws Exception {

        RegistrationDTO dto = (RegistrationDTO) command;
        ModelAndView mv = new ModelAndView("redirect:profile.htm");
        LOGGER.info("ModelAndView return "+mv);

        return mv;
    }
}
